Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set required attribute in the html elements #2170

Merged
merged 3 commits into from
Jan 22, 2015

Conversation

krishan1390
Copy link
Contributor

Set required attribute in the html field and text elements based on the required flag on the field

Set required attribute in the html element based on the required flag on the field
Set required attribute in the html text element based on the required flag on the field
@mshibuya
Copy link
Member

Spec needed!

@krishan1390
Copy link
Contributor Author

We can set the required flag for a field in a model using:

rails_admin do
  edit do
    field :name do
      required :true
    end
  end
end

But this doesn't set the required attribute for the corresponding html input fields.

image

All it does is create a required label below the input field.
image

There is no client side validation and hence the form can be submitted without any value.

This fix is to set the required attribute for the text fields based on the above configuration.

@mshibuya
Copy link
Member

Oh, I'm sorry I wasn't clear.
We should have some RSpec test examples to ensure this change does not break in future.

I think they should be written here:
https://github.com/sferik/rails_admin/blob/master/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb

@krishan1390
Copy link
Contributor Author

Done

mshibuya added a commit that referenced this pull request Jan 22, 2015
Set required attribute in the html elements
@mshibuya mshibuya merged commit e612d50 into railsadminteam:master Jan 22, 2015
@mshibuya
Copy link
Member

Thanks! 👍

@krishan1390
Copy link
Contributor Author

Can you please take a look at #2171

Basically I also need it for the form_filtering_select and the form_filtering_multiselect partials

If I write this:

= form.select field.method_name, collection, { selected: selected_id, include_blank: true }, field.html_attributes.reverse_merge({ data: { filteringselect: true, options: js_data.to_json }, placeholder: t('admin.misc.search'), required: field.required })

The required attribute is set to the "select" element. But this is invalid because it needs to be set to the autocomplete "input" element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants